<?php


namespace app\user\controller;


use app\common\controller\Api;
use app\user\model\AddressModel;
use app\user\model\DetailModel;

class Placeorder extends Base
{
    protected $noNeedLogin = '*';

    public function index()
    {

//            $user_id = input('user_id/d');
//            $productid = input('productid/d');
            $data = input('get.');
            if (empty($data['user_id'])) {
                $this->error('用户id不能为空');
            }
            $address = AddressModel::order('id','DESC')
                ->where('user_id',$data['user_id'])
                ->field('id,name,mobile,area,address')
                ->find();
            if (!$address){
                $this->error('该用户下没有地址');
            }
            if (empty($data['productid'])){
                $this->error('产品ID不能为空');
            }

            $list = DetailModel::where('id',$data['productid'])
                ->order('sales DESC,money DESC')
                ->field('id,image,profilee,money,deposit')
                ->find();
            $sum = round($list['money'] + $list['deposit'],2);
            if (!$list){
                $this->error('不存在');
            }
            $this->success('查询成功',[
                'address' => $address,
                'list' => $list,
                'sum' => $sum
            ]);


    }

}